const nameMaps = {}
/**
 * 增强路由
 * 给路由添加 name
 * @param routes
 */
export default function enhanceRouter(routes) {
  routes.forEach(route => {
    const {path, name, children} = route

    if(name || !path) return

    const arr = path.split('/')
    const _name = arr[arr.length - 1]
    if(!nameMaps[_name]) {
      route.name = _name
      nameMaps[_name] = _name
    }

    if(children) {
      enhanceRouter(children)
    }
  })
}
